package com.sjzn.module_park.fragment

import android.annotation.SuppressLint
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.bumptech.glide.Glide
import com.czl.base.base.BaseFragment
import com.czl.base.config.AppConstants
import com.czl.base.data.bean.ReverseSearchBean
import com.czl.base.event.LiveBusCenter
import com.czl.module_park.R
import com.czl.module_park.BR
import com.czl.module_park.databinding.FragmentReveseCarDetailBinding
import com.sjzn.module_park.viewmodel.ReveseSearchCarDetailViewModel

@Route(path = AppConstants.Router.Park.F_REVERSE_CAR_SEARCH_DETAIL)
class ReveseSearchCarDetailFragment:
    BaseFragment<FragmentReveseCarDetailBinding, ReveseSearchCarDetailViewModel>() {
    var reverseCar: ReverseSearchBean.DataItem? = null
    override fun initContentView(): Int {
        return R.layout.fragment_revese_car_detail
    }

    override fun initVariableId(): Int {
        return BR.viewModel
    }

    @SuppressLint("SetTextI18n")
    override fun initData() {
        viewModel.tvTitle.set("反向寻车详情")
        reverseCar=arguments?.getSerializable(AppConstants.BundleKey.MONTH_CARD_DATA) as ReverseSearchBean.DataItem
        binding.tvReveseDetailContentCar.text= reverseCar!!.carNo
        binding.tvReveseDetailContentPark.text= reverseCar!!.areaName+ reverseCar!!.layName+ reverseCar!!.carPlace
        context?.let { Glide.with(it).load(reverseCar!!.carImgPath).into(binding.ivCar) }
    }

    override fun initViewObservable() {
        binding.btnPay.setOnClickListener {
            startContainerActivity(
                AppConstants.Router.Park.F_PARK_DETAIL,
                Bundle().apply {
                    putString(AppConstants.BundleKey.VEHICLE_NO_KEY, reverseCar!!.carNo)
                })

        }
        LiveBusCenter.observePayResultEvent(this, {
            when (it.payType) {
                AppConstants.Constants.PAY_SUCCESS_TYPE-> {
                    back()
                }
            }
        })
    }
}